"""Pydantic请求模型：校验前端传入参数，确保数据格式正确"""
from typing import List, Optional, Dict
from pydantic import BaseModel, Field
from config.constants import ROLE_SYSTEM, DEFAULT_SESSION_TITLE

class ChatRequest(BaseModel):
    """对话请求模型（/chat接口）"""
    query: str = Field(..., description="用户输入的提问内容")
    sys_prompt: str = Field(
        default=ROLE_SYSTEM, 
        description="系统提示词（定义AI角色）"
    )
    history: List[Dict[str, str]] = Field(
        default=[], 
        description="前端传递的历史对话（格式：[{role, content}, ...]）"
    )
    history_len: int = Field(
        default=5, 
        ge=0,  # 大于等于0
        description="保留的历史对话轮数（0表示不保留）"
    )
    temperature: float = Field(
        default=0.5, 
        ge=0.0, le=1.0,  # 0.0~1.0范围
        description="大模型采样温度（值越高越随机）"
    )
    top_p: float = Field(
        default=0.5, 
        ge=0.0, le=1.0,
        description="大模型采样概率（与temperature二选一用）"
    )
    max_token: Optional[int] = Field(
        default=None, 
        ge=1,  # 至少1个Token
        description="大模型生成的最大Token数（None用模型默认）"
    )
    session_id: Optional[str] = Field(
        default=None, 
        description="对话会话ID（关联历史记录，新会话可不传）"
    )
    user_id: str = Field(
        ...,  # 必传
        description="当前登录用户ID（从Node.js系统获取，用于数据隔离）"
    )
    stream: bool = False   # 添加这个字段，默认值为False

class CreateSessionRequest(BaseModel):
    """创建会话请求模型（/chat/sessions接口）"""
    user_id: str = Field(..., description="当前登录用户ID")
    title: str = Field(
        default=DEFAULT_SESSION_TITLE, 
        max_length=30,
        description="会话标题（默认：新对话）"
    )